/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */


//#define BOOST_TEST_MODULE CastlingAvailability
#include <boost/test/unit_test.hpp>
#include "../config.h"


BOOST_AUTO_TEST_SUITE( CastlingAvailabilityTest )

const std::string CAS[] = {
		"KQkq","KQk","KQq","Kkq","Qkq","KQ","Kq","kq","Kk","Qq","Qk","K","Q","k","q","-"
	};

BOOST_AUTO_TEST_CASE( testWhiteQueen ) {
	CastlingAvailability ca;
	ca.setWhiteQueen();
	BOOST_CHECK(ca.whiteQueen());
	BOOST_CHECK(ca.queen(Color::WHITE()));
	ca.setWhiteQueen();
	BOOST_CHECK(ca.whiteQueen());
	BOOST_CHECK(ca.queen(Color::WHITE()));
	ca.unsetWhiteQueen();
	BOOST_CHECK(!ca.whiteQueen());
	BOOST_CHECK(!ca.queen(Color::WHITE()));
	ca.unsetWhiteQueen();
	BOOST_CHECK(!ca.whiteQueen());
	BOOST_CHECK(!ca.queen(Color::WHITE()));
	ca.setWhiteQueen();
	ca.unsetQueen(Color::WHITE());
	BOOST_CHECK(!ca.queen(Color::WHITE()));
}

BOOST_AUTO_TEST_CASE( testBlackQueen ) {
	CastlingAvailability ca;
	ca.setBlackQueen();
	BOOST_CHECK(ca.blackQueen());
	BOOST_CHECK(ca.queen(Color::BLACK()));
	ca.setBlackQueen();
	BOOST_CHECK(ca.blackQueen());
	BOOST_CHECK(ca.queen(Color::BLACK()));
	ca.unsetBlackQueen();
	BOOST_CHECK(!ca.blackQueen());
	BOOST_CHECK(!ca.queen(Color::BLACK()));
	ca.unsetBlackQueen();
	BOOST_CHECK(!ca.blackQueen());
	BOOST_CHECK(!ca.queen(Color::BLACK()));
	ca.setBlackQueen();
	ca.unsetQueen(Color::BLACK());
	BOOST_CHECK(!ca.queen(Color::BLACK()));
}

BOOST_AUTO_TEST_CASE( testWhiteKing ) {
	CastlingAvailability ca;
	ca.setWhiteKing();
	BOOST_CHECK(ca.whiteKing());
	BOOST_CHECK(ca.king(Color::WHITE()));
	ca.setWhiteKing();
	BOOST_CHECK(ca.whiteKing());
	BOOST_CHECK(ca.king(Color::WHITE()));
	ca.unsetWhiteKing();
	BOOST_CHECK(!ca.whiteKing());
	BOOST_CHECK(!ca.king(Color::WHITE()));
	ca.unsetWhiteKing();
	BOOST_CHECK(!ca.whiteKing());
	BOOST_CHECK(!ca.king(Color::WHITE()));
	ca.setWhiteKing();
	ca.unsetKing(Color::WHITE());
	BOOST_CHECK(!ca.king(Color::WHITE()));
}

BOOST_AUTO_TEST_CASE( testBlackKing ) {
	CastlingAvailability ca;
	ca.setBlackKing();
	BOOST_CHECK(ca.blackKing());
	BOOST_CHECK(ca.king(Color::BLACK()));
	ca.setBlackKing();
	BOOST_CHECK(ca.blackKing());
	BOOST_CHECK(ca.king(Color::BLACK()));
	ca.unsetBlackKing();
	BOOST_CHECK(!ca.blackKing());
	BOOST_CHECK(!ca.king(Color::BLACK()));
	ca.unsetBlackKing();
	BOOST_CHECK(!ca.blackKing());
	BOOST_CHECK(!ca.king(Color::BLACK()));
	ca.setBlackKing();
	ca.unsetKing(Color::BLACK());
	BOOST_CHECK(!ca.king(Color::BLACK()));
}

BOOST_AUTO_TEST_CASE( testClear ) {
	CastlingAvailability ca;
	ca.clear();
	BOOST_CHECK(!ca.blackKing());
	BOOST_CHECK(!ca.blackQueen());
	BOOST_CHECK(!ca.whiteKing());
	BOOST_CHECK(!ca.whiteQueen());
}

BOOST_AUTO_TEST_CASE( testUnset ) {
	CastlingAvailability ca;
	ca.clear();
	ca.setBlackKing();
	ca.setWhiteKing();
	ca.setBlackQueen();
	ca.setWhiteQueen();
	ca.unset(Color::WHITE());
	BOOST_CHECK(ca.blackKing());
	BOOST_CHECK(ca.blackQueen());
	BOOST_CHECK(!ca.whiteKing());
	BOOST_CHECK(!ca.whiteQueen());
	ca.setWhiteKing();
	ca.setWhiteQueen();
	ca.unset(Color::BLACK());
	BOOST_CHECK(!ca.blackKing());
	BOOST_CHECK(!ca.blackQueen());
	BOOST_CHECK(ca.whiteKing());
	BOOST_CHECK(ca.whiteQueen());
}

BOOST_AUTO_TEST_CASE( testWhite ) {
	CastlingAvailability ca;
	ca.clear();
	BOOST_CHECK(!ca.white());
	ca.setBlackKing();
	BOOST_CHECK(!ca.white());
	ca.setBlackQueen();
	BOOST_CHECK(!ca.white());
	ca.unsetBlackKing();
	BOOST_CHECK(!ca.white());
	ca.setWhiteKing();
	BOOST_CHECK(ca.white());
	ca.setWhiteQueen();
	BOOST_CHECK(ca.white());
	ca.unsetWhiteKing();
	BOOST_CHECK(ca.white());
	ca.unsetBlackQueen();
	BOOST_CHECK(ca.white());
	ca.setWhiteKing();
	BOOST_CHECK(ca.white());
}

BOOST_AUTO_TEST_CASE( testBlack ) {
	CastlingAvailability ca;
	ca.clear();
	BOOST_CHECK(!ca.black());
	ca.setWhiteKing();
	BOOST_CHECK(!ca.black());
	ca.setWhiteQueen();
	BOOST_CHECK(!ca.black());
	ca.unsetWhiteKing();
	BOOST_CHECK(!ca.black());
	ca.setBlackKing();
	BOOST_CHECK(ca.black());
	ca.setBlackQueen();
	BOOST_CHECK(ca.black());
	ca.unsetBlackKing();
	BOOST_CHECK(ca.black());
	ca.unsetWhiteQueen();
	BOOST_CHECK(ca.black());
	ca.setBlackKing();
	BOOST_CHECK(ca.black());
}

BOOST_AUTO_TEST_CASE( testToStrAndFromStr ) {
	CastlingAvailability ca;
	for ( int i = 0; i < 16; ++i ) {
		ca.fromStr(CAS[i]);
		BOOST_CHECK_EQUAL(ca.toStr(), CAS[i]);
	}
}



BOOST_AUTO_TEST_SUITE_END()
